<template>
	<el-dialog title="提示" :visible.sync="visible" width="30%">
		<el-date-picker v-model="createTime" type="month" value-format="yyyy-MM-dd HH:mm:ss" placeholder="导出月份"></el-date-picker>
		<span slot="footer" class="dialog-footer">
	    	<el-button @click="handleClose" size="small">取 消</el-button>
	    	<el-button type="primary" @click="doSure" :loading="exporting" size="small">确 定</el-button>
	  	</span>
	</el-dialog>
</template>

<script>
import { exportDoctor } from '@/api/doctor'
import { exportPatient } from "@/api/patient";
export default {
	props: {
		visible: {
			type: Boolean,
			default: () => false
		},
		busType: {
			type: String,
			default: () => undefined
		}
	},
	data() {
		return {
			createTime: undefined,
			exporting: false
		};
	},
	mounted() {

	},
	methods: {
		handleClose() {
			this.$emit('update:visible', false);
		},
		doSure() {
			if (this.createTime) {
				this.exporting = true;
				if (this.busType === 'doctor') {
					exportDoctor({ createTime: this.createTime }).then(res => {
						this.doDownload(res);
					})
				} else if (this.busType === 'patient') {
					exportPatient({ createTime: this.createTime }).then(res => {
						this.doDownload(res);
					})
				}

			}
		},
		doDownload(res) {
			if (res.code === 200) {
				this.download(res.msg);
				this.exporting = false;
				this.handleClose();
			}
		}
	}
}
</script>

<style lang="scss" scoped>

</style>
